Sketch in NMEA file reader.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 10 Feb 2004 04:52:05 +0000 (04:52 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 10 Feb 2004 04:52:05 +0000 (04:52 +0000)
gpsbabel/Makefile
gpsbabel/gpx.c
gpsbabel/nmea.c [new file with mode: 0644]
gpsbabel/vecs.c

index e447049a462af05e8392588358c5227e107f20f7..7167fa63def02b0fd1c99bdd58beccb965c25b94 100644 (file)
@@ -19,7 +19,7 @@ FMTS=magproto.o gpx.o geo.o mapsend.o mapsource.o \
        psp.o holux.o garmin.o tmpro.o tpg.o \
        xcsv.o gcdb.o tiger.o internal_styles.o easygps.o quovadis.o \
        gpilots.o saroute.o navicache.o psitrex.o geoniche.o delgpl.o \
-       ozi.o
+       ozi.o nmea.o
 
 FILTERS=position.o duplicate.o arcdist.o polygon.o smplrout.o reverse_route.o
 
index 694b2ead7ca233070bb6b48f4c644a460d48f289..48f54123530d1a46ff05c25d3f986c78dbc34e0e 100644 (file)
@@ -1183,7 +1183,7 @@ gpx_write(void)
 
        gpx_write_time( now, "time" );
        waypt_compute_bounds(&bounds);
-       if (bounds.max_lat  360) {
+       if (bounds.max_lat  > -360) {
                fprintf(ofd, "<bounds minlat=\"%f\" minlon =\"%f\" "
                               "maxlat=\"%f\" maxlon=\"%f\" />\n",
                               bounds.min_lat, bounds.min_lon, 
diff --git a/gpsbabel/nmea.c b/gpsbabel/nmea.c
new file mode 100644 (file)
index 0000000..acb1b3c
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+    Read files containing selected NMEA 0183 sentences.
+    Based on information by Eino Uikkanenj
+
+    Copyright (C) 2004 Robert Lipe, robertlipe@usa.net
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+#include <ctype.h>
+#include <time.h>
+
+#include "defs.h"
+
+/**********************************************************
+
+   ' 1      2      3        4 5         6 7 8  9   10   11 12  13 14 15
+   ' $GPGGA - Global Positioning System Fix Data
+   ' $GPGGA,155537,6006.718,N,02426.290,E,1,05,2.4,50.5,M,19.7,M,,*79
+   '  2    123519       Fix taken at 12:35:19 UTC
+   '  3,4  4807.038,N   Latitude 48 deg 07.038' N
+   '  5,6  01131.324,E  Longitude 11 deg 31.324' E
+   '  7    1            Fix quality: 0 = invalid
+   '                                 1 = GPS fix
+   '                                 2 = DGPS fix
+   '  8    08           Number of satellites being tracked
+   '  9    0.9          Horizontal dilution of position
+   ' 10,11 545.4,M      Altitude, Metres, above mean sea level
+   ' 12,13 46.9,M       Height of geoid (mean sea level) above WGS84 ellipsoid
+   ' 14    (empty field) time in seconds since last DGPS update
+   ' 15    (empty field) DGPS station ID number
+
+   ' $GPWPL - waypoint location
+   ' $GPWPL,4917.16,N,12310.64,W,003*65
+   '  2,3  4917.16,N    Latitude of waypoint
+   '  4,5  12310.64,W   Longitude of waypoint
+   '  6    003          Waypoint ID
+
+   ' $GPGLL - Geographic position, Latitude and Longitude
+   ' $GPGLL,4916.45,N,12311.12,W,225444,A
+   '  2,3  4916.46,N    Latitude 49 deg. 16.45 min. North
+   '  4,5  12311.12,W   Longitude 123 deg. 11.12 min. West
+   '  6    225444       Fix taken at 22:54:44 UTC
+   '  7    A            Data valid
+
+   ' The optional checksum field consists of a "*" and two hex digits repre-
+   ' senting the exclusive OR of all characters between, but not including,
+   ' the "$" and "*".  A checksum is required on some sentences.
+
+****************************************/
+
+static FILE *file_in;
+static FILE *file_out;
+static route_head *trk_head;
+
+#define MYNAME "nmea"
+
+static void
+nmea_rd_init(const char *fname)
+{
+       file_in = xfopen(fname, "r", MYNAME);
+}
+static  void
+nmea_rd_deinit(void)
+{
+       fclose(file_in);
+}
+
+static void
+nmea_wr_init(const char *portname)
+{
+       file_out = xfopen(portname, "w+", MYNAME);
+}
+
+static  void
+nmea_wr_deinit(void)
+{
+       fclose(file_out);
+}
+
+void
+gpgll_parse(char *ibuf)
+{
+       double latdeg, lngdeg;
+       char lngdir, latdir;
+       int hms;
+       char valid;
+       struct tm tm;
+       waypoint *waypt;
+
+       if (trk_head == NULL) {
+               trk_head = route_head_alloc();
+               track_add_head(trk_head);
+       }
+
+       waypt = waypt_new();
+
+       memset(&tm, 0, sizeof(tm));
+
+       sscanf(ibuf,"$GPGLL,%lf,%c,%lf,%c,%d,%c,",
+               &latdeg,&latdir,
+               &lngdeg,&lngdir,
+               &hms,&valid);
+
+       tm.tm_sec = hms % 100;
+       hms = hms / 100;
+       tm.tm_min = hms % 100;
+       hms = hms / 100;
+       tm.tm_hour = hms % 100;
+
+       waypt->creation_time = mktime(&tm) + get_tz_offset() + time(0);;
+
+       if (latdir == 'S') latdeg = -latdeg;
+       waypt->latitude = ddmm2degrees(latdeg);
+
+       if (lngdir == 'W') lngdeg = -lngdeg;
+       waypt->longitude = ddmm2degrees(lngdeg);
+
+       route_add_wpt(trk_head, waypt);
+}
+
+static void
+gpgga_parse(char *ibuf)
+{
+       double latdeg, lngdeg;
+       char lngdir, latdir;
+       int hms;
+       int fix;
+       int nsats;
+       double hdop;
+       struct tm tm;
+       double alt;
+       char altunits;
+       waypoint *waypt;
+
+       if (trk_head == NULL) {
+               trk_head = route_head_alloc();
+               track_add_head(trk_head);
+       }
+
+       waypt  = waypt_new();
+
+       memset(&tm, 0, sizeof(tm));
+
+       sscanf(ibuf,"$GPGGA,%d,%lf,%c,%lf,%c,%d,%d,%lf,%lf,%c",
+               &hms, &latdeg,&latdir,
+               &lngdeg,&lngdir,
+               &fix,&nsats,&hdop,&alt,&altunits);
+
+       tm.tm_sec = hms % 100;
+       hms = hms / 100;
+       tm.tm_min = hms % 100;
+       hms = hms / 100;
+       tm.tm_hour = hms % 100;
+
+       waypt->creation_time = mktime(&tm) + get_tz_offset() + time(NULL);
+
+       if (latdir == 'S') latdeg = -latdeg;
+       waypt->latitude = ddmm2degrees(latdeg);
+
+       if (lngdir == 'W') lngdeg = -lngdeg;
+       waypt->longitude = ddmm2degrees(lngdeg);
+
+       waypt->altitude = alt;
+       route_add_wpt(trk_head, waypt);
+
+}
+
+static void
+nmea_read(void)
+{
+       char ibuf[1024];
+
+       while (fgets(ibuf, sizeof(ibuf), file_in)) {
+               if (0 == strncmp(ibuf, "$GPGGA,", 7)) {
+                       gpgga_parse(ibuf);
+               }
+//             if (0 == strncmp(ibuf, "$GPGLL,", 7)) {
+//                     gpgll_parse(ibuf);
+//             }
+       }
+}
+
+static void
+nmea_write(void)
+{
+}
+
+ff_vecs_t nmea_vecs = {
+       nmea_rd_init,   
+       nmea_wr_init,   
+       nmea_rd_deinit, 
+       nmea_wr_deinit, 
+       nmea_read,
+       NULL,
+       NULL
+};
index 4a828dd3f5e54529cf049e06290353aadafc7310..23258201efb0ed04d0e1f1852b65f3ec6a3a707e 100644 (file)
@@ -58,6 +58,7 @@ extern ff_vecs_t psit_vecs;             /* MRCB */
 extern ff_vecs_t geoniche_vecs;
 extern ff_vecs_t gpl_vecs;
 extern ff_vecs_t ozi_vecs;
+extern ff_vecs_t nmea_vecs;
 
 static
 vecs_t vec_list[] = {
@@ -230,6 +231,12 @@ vecs_t vec_list[] = {
                "OziExplorer",
                NULL
        },
+       {
+               &nmea_vecs,
+               "nmea",
+               "NMEA 0183 sentences",
+               NULL
+       },
        {
                NULL,
                NULL,